#!/usr/bin/env ruby
# 
# 
begin
  require 'rubygems' 
rescue LoadError
end


$globalOSType = "unknown"
platform = RUBY_PLATFORM.downcase
if( platform =~ /mswin(?!ce)|mingw|cygwin|bccwin/ )
	$globalOSType = "mswin"
end
if( platform =~ /linux/ )
	$globalOSType = "linux"
end



require 'wx'
include Wx
require 'pathname'

# 根据自身目录得到，运行目录

tmpPath = Pathname.new(__FILE__)
tmpPath = tmpPath.realpath()

tmpPath = tmpPath.parent()
tmpPath = tmpPath.parent()
tmpPath = tmpPath.parent()
$globalTTPathRoot = tmpPath.to_s()

tmpPath = Pathname.pwd()
$globalTTPathPWD = tmpPath.to_s()

$globalTTPathAppHome = $globalTTPathRoot +"/tt-app"
$globalTTPathAppBin = $globalTTPathAppHome +"/bin"
$globalTTPathRubyScrip = $globalTTPathAppHome +"/rubyScript"
$globalTTPathRubyScripExtLib = $globalTTPathRubyScrip+"/extLibs"
$globalTTPathRubyResource = $globalTTPathAppHome +"/xrcResource"
$globalTTPathRubyTemplate = $globalTTPathAppHome +"/templates"

$LOAD_PATH.push( $globalTTPathRubyScrip )
$LOAD_PATH.push( $globalTTPathRubyScripExtLib )

require 'ttWxMainFrame'

require 'ttProjectManager'
require 'ttTaskManager'

$globalProjectMgr = ProjectManagerClass.new()
$globalTaskMgr = TaskManagerClass.new()

$globalProjectPath = nil
if ARGV[0] then
	tmpProjectPath = Pathname.new(ARGV[0])
	if tmpProjectPath.exist?() then
		$globalProjectPath = tmpProjectPath
	end
end
if $globalProjectPath then
	$globalProjectHome = $globalProjectPath.dirname()
end

class MainApp < App
  def on_init
	@frame=MainFrame.new()
	if $globalProjectPath then
		$globalProjectMgr.loadFile($globalProjectPath);
		@frame.reloadProject()
	end
    @frame.show(TRUE)
  end
  def on_exit
    puts("TTCode exit")
	$globalProjectMgr.saveFile()
  end
end

appInstance = MainApp.new
appInstance.main_loop()
GC.start
puts("survived gc")
